<?php
if(checkAdmin()){
?>
	<script language="javascript" src="js/graphics.js"></script>
	<?php
		if(isset($_POST['submit'])){
			if(strlen($_POST['colorName']) > 0){
				require_once("classes/Color.class.php");
				$color = new Color($_POST);
				$color->save();
			}
			else
			{
				echo '<div class="centered">'.getErrMess(36).'</div>';
			}
		}
	?>
	<h2>Gérer les couleurs</h2>
	<p>Les couleurs doivent être saisies au format RGB (valeurs de 0 à 255).</p>
	<div class="centered">
		<div id="elementList">
			<?php
				require_once("classes/HumeurDatabase.class.php");
				require_once("classes/Galery.class.php");
				require_once("classes/Color.class.php");
				$bd = new HumeurDatabase();
				$bd->connect();
				$gallery = new Galery('',error("Aucune couleur n'est disponible pour le moment."));
				$allColors = $bd->selectAll("colors");
				while($colorData = mysql_fetch_assoc($allColors)){
					$color = new Color($colorData);
					$gallery->push($color);
				}
				echo $gallery;
			?>
            <div id="newElement">
                <div style="padding-top:2px" class="existingColorBloc centered edited">
                    <div class="colorForm">
                        <form action="" method="post">
                                <input style="width:120px;" type="text" name="colorName" placeholder="Nom de la couleur"/><br/>
                                <div id="newShape"></div>
                                <div>
                                    <input style="margin:0 4px;" class="leftFloat colorQuantity red" value="0" onkeyup="createShape('newShape','createCircle',document.getElementById('redQuantity').value,document.getElementById('greenQuantity').value,document.getElementById('blueQuantity').value)" type="text" name="redQuantity" id="redQuantity"/> 
                                    <input style="margin:0 4px;" class="leftFloat colorQuantity green" value="0" onkeyup="createShape('newShape','createCircle',document.getElementById('redQuantity').value,document.getElementById('greenQuantity').value,document.getElementById('blueQuantity').value)" type="text" name="greenQuantity" id="greenQuantity"/>
                                    <input style="margin:0 4px;" class="leftFloat colorQuantity blue" value="0" onkeyup="createShape('newShape','createCircle',document.getElementById('redQuantity').value,document.getElementById('greenQuantity').value,document.getElementById('blueQuantity').value)" type="text" name="blueQuantity" id="blueQuantity"/>
                            	</div>
                            <input value="Créer" type="submit" name="submit">
                        </form>
                    </div>
                </div>
			</div>
		</div>
	</div>
	<div class="centered"><span class="buttonBloc grey"><a href="index.php?module=myaccount"><img src="img/back.png" alt="Retour"/>Retour au compte</a></span></div>
	<script>createShape('newShape','createCircle',document.getElementById('redQuantity').value,document.getElementById('greenQuantity').value,document.getElementById('blueQuantity').value)</script>
<?php
}
?>